//
//  DBRespiratory.m
//  CareRingApp
//
//  Created by Linktop on 2024/2/5.
//

#import "DBRespiratory.h"
#import "DBHistoryDataSr03.h"
@implementation DBRespiratory


+(void)query:(NSString * _Nonnull)macAddress
       Begin:(NSTimeInterval)beginTime
         End:(NSTimeInterval)endTime
        Desc:(BOOL)isDesc
    Cpmplete:(void(^)(NSMutableArray<DBRespiratory *> * results) )cmpBlk
{
    if (!macAddress.length) {
        return;
    }
    
    [DBHistoryDataSr03 queryBy:macAddress Begin:[NSDate dateWithTimeIntervalSince1970:beginTime] End:[NSDate dateWithTimeIntervalSince1970:endTime] OrderBeTimeDesc:isDesc Cpmplete:^(NSMutableArray<DBHistoryDataSr03 *> * _Nonnull results) {
        
        NSMutableArray<DBRespiratory *> *oxygenRes = [NSMutableArray new];
        for (DBHistoryDataSr03 *hisObj in results) {
            
            if (hisObj.respiratory.intValue > 0 && hisObj.respiratory.intValue <= 35 ) {
                DBRespiratory *respiraModel = [[DBRespiratory alloc]init];
                
                respiraModel.value = hisObj.respiratory;//@([rs doubleForColumn:@"value"]);
                respiraModel.time = [NSDate dateWithTimeIntervalSince1970:hisObj.time.doubleValue];//[rs dateForColumn:@"time"];
                respiraModel.macAddress = macAddress;//[rs stringForColumn:@"account"];
                respiraModel.battery = hisObj.battery;
                
                [oxygenRes addObject:respiraModel];
            }
           
        }
        
        if (cmpBlk) {
            dispatch_async(dispatch_get_main_queue(), ^{
                cmpBlk(oxygenRes);
            });
        }
        
    }];
    
}
@end
